From d05e0d492481c857c42e4802217fb86704966aa0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jul 2017 19:11:36 +0300 Subject: [PATCH] Make layout private to targets --- src/cargo/util/toml/mod.rs | 22 +++++++++++----------- src/cargo/util/toml/targets.rs | 27 ++++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e96bed4ae..e2c7d08f9 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -22,7 +22,7 @@ use util::{self, ToUrl, Config}; use util::errors::{CargoError, CargoResult, CargoResultExt}; mod targets; -use self::targets::{Layout, targets}; +use self::targets::targets; pub fn read_manifest(path: &Path, source_id: &SourceId, config: &Config) -> CargoResult<(EitherManifest, Vec)> { @@ -39,8 +39,7 @@ fn do_read_manifest(contents: &str, source_id: &SourceId, config: &Config) -> CargoResult<(EitherManifest, Vec)> { - let root = manifest_file.parent().unwrap(); - let layout = Layout::from_project_path(root); + let project_root = manifest_file.parent().unwrap(); let toml = { let pretty_filename = util::without_prefix(manifest_file, config.cwd()).unwrap_or(manifest_file); @@ -57,7 +56,7 @@ fn do_read_manifest(contents: &str, let manifest = Rc::new(manifest); return match TomlManifest::to_real_manifest(&manifest, source_id, - &layout, + project_root, config) { Ok((mut manifest, paths)) => { for key in unused { @@ -73,7 +72,7 @@ fn do_read_manifest(contents: &str, Err(e) => { match TomlManifest::to_virtual_manifest(&manifest, source_id, - &root, + project_root, config) { Ok((m, paths)) => Ok((EitherManifest::Virtual(m), paths)), Err(..) => Err(e), @@ -496,7 +495,7 @@ impl TomlManifest { fn to_real_manifest(me: &Rc, source_id: &SourceId, - layout: &Layout, + project_root: &Path, config: &Config) -> CargoResult<(Manifest, Vec)> { let mut nested_paths = vec![]; @@ -517,13 +516,13 @@ impl TomlManifest { // If we have no lib at all, use the inferred lib if available // If we have a lib with a path, we're done // If we have a lib with no path, use the inferred lib or_else package name - let targets = targets(me, layout, project_name, &project.build)?; + let targets = targets(me, project_root, project_name, &project.build)?; if targets.is_empty() { debug!("manifest has no build targets"); } - if let Err(e) = unique_build_targets(&targets, layout) { + if let Err(e) = unique_build_targets(&targets, project_root) { warnings.push(format!("file found to be present in multiple \ build targets: {}", e)); } @@ -541,7 +540,7 @@ impl TomlManifest { config: config, warnings: &mut warnings, platform: None, - root: &layout.root, + root: project_root, }; fn process_dependencies( @@ -773,9 +772,9 @@ impl TomlManifest { /// Will check a list of build targets, and make sure the target names are unique within a vector. /// If not, the name of the offending build target is returned. -fn unique_build_targets(targets: &[Target], layout: &Layout) -> Result<(), String> { +fn unique_build_targets(targets: &[Target], project_root: &Path) -> Result<(), String> { let mut seen = HashSet::new(); - for v in targets.iter().map(|e| layout.root.join(e.src_path())) { + for v in targets.iter().map(|e| project_root.join(e.src_path())) { if !seen.insert(v.clone()) { return Err(v.display().to_string()); } @@ -894,6 +893,7 @@ impl TomlDependency { } #[derive(Default, Serialize, Deserialize, Debug, Clone)] +pub struct TomlTarget { name: Option, diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 3e9f03ef0..588b2d676 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -21,13 +21,13 @@ use super::{TomlTarget, LibKind, PathValue, TomlManifest, StringOrBool, /// Implicit Cargo targets, defined by conventions. -pub struct Layout { - pub root: PathBuf, - pub lib: Option, - pub bins: Vec, - pub examples: Vec, - pub tests: Vec, - pub benches: Vec, +struct Layout { + root: PathBuf, + lib: Option, + bins: Vec, + examples: Vec, + tests: Vec, + benches: Vec, } impl Layout { @@ -109,7 +109,8 @@ fn try_add_files(files: &mut Vec, root: PathBuf) { /* else just don't add anything if the directory doesn't exist, etc. */ } -pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_build: &Option) -> CargoResult> { +pub fn targets(me: &TomlManifest, project_root: &Path, project_name: &str, custom_build: &Option) -> CargoResult> { + let layout = Layout::from_project_path(project_root); let lib = match me.lib { Some(ref lib) => { lib.validate_library_name()?; @@ -124,7 +125,7 @@ pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_bu } ) } - None => inferred_lib_target(project_name, layout), + None => inferred_lib_target(project_name, &layout), }; let bins = match me.bin { @@ -134,7 +135,7 @@ pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_bu }; bins.clone() } - None => inferred_bin_targets(project_name, layout) + None => inferred_bin_targets(project_name, &layout) }; for bin in bins.iter() { @@ -151,7 +152,7 @@ pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_bu } examples.clone() } - None => inferred_example_targets(layout) + None => inferred_example_targets(&layout) }; let tests = match me.test { @@ -161,7 +162,7 @@ pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_bu } tests.clone() } - None => inferred_test_targets(layout) + None => inferred_test_targets(&layout) }; let benches = match me.bench { @@ -171,7 +172,7 @@ pub fn targets(me: &TomlManifest, layout: &Layout, project_name: &str, custom_bu } benches.clone() } - None => inferred_bench_targets(layout) + None => inferred_bench_targets(&layout) }; if let Err(e) = unique_names_in_targets(&bins) { -- 2.30.2